<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Install_model extends CI_Model {

	function __construct()
	{
		parent::__construct();
		$this->load->dbforge();
	}

	function check_dirs()
	{

	}

	function check_database()
	{

	}

	function create_config_file()
	{

	}

	function edit_setting($setting, $value)
	{

	}

	function check_session()
	{
		$this->load->library('session');
		$this->session->set_userdata('test', 'yes');
		return $this->session->userdata('test') === 'yes' ? TRUE : FALSE;
	}

	function create_ci_session_table($table = 'ci_sessions')
	{
		$this->dbforge->drop_table($table);
		$this->dbforge->add_field(
			array(
				'session_id' => array(
					'type' => 'VARCHAR',
					'constraint' => 40,
					'default' => 0,
					'null' => FALSE
				),
				'ip_address' => array(
					'type' => 'VARCHAR',
					'constraint' => 16,
					'default' => 0
				),
				'user_agent' => array(
					'type' => 'VARCHAR',
					'constraint' => 120
				),
				'last_activity' => array(
					'type' => 'INT',
					'constraint' => 10,
					'unsigned' => TRUE,
					'default' => 0
				),
				'user_data' => array(
					'type' => 'text'
				),
			)
		);
		$this->dbforge->add_key('session_id', TRUE); // primary key
		$this->dbforge->create_table($table, TRUE);

		// Nasty hack here until dbforge can have different key -> field names
		$this->db->query("ALTER TABLE `$table` ADD KEY `last_activity_idx` ".
			"(`last_activity`)");
		return TRUE;
	}
}